package cn.cdeden.resource.api.domain;

import cn.cdeden.common.oss.enumd.OssBucketOneEnum;
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName : KnowCore01
 * @Package : cn.cdeden.resource.api.domain
 * @ClassName : RemoteFilesInfo
 * @Author : Yu.
 * @Description : // 上传文件 获取文件应该去的桶 中的位置
 * @Date : 2024/12/5 16:13
 * @Version : 1.0
 */
@Data
@NoArgsConstructor
public class RemoteFilesBucketPath<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 如果放回这个字段这是在移动为历史版本
     **/
    private String storageId;


    /**
     * 文件要移动到的桶
     **/
    private String bucketName;

    /**
     * 其他信息  用于放回前端数据
     **/
    private T info;




//    public Object getInfo(){
//        try {
//            JSONObject jsonObject = JSONObject.parseObject((String) info);
//            return jsonObject;
//        }catch (Exception e){
//        }
//        return info;
//    }




    /**
     * 返回不同模块的编号
     */
    private String  moduleId;


    /**
     * 是否有权限
     */
    private boolean isPurview;

    /**
     * 哪些用户拥有该文件
     */
    private List<String> userIdList;

    /**
     * 哪些角色拥有该文件
     */
    private List<String> roleIdList;

    /**
     * 哪些部门拥有该文件
     */
    private List<String> deptIdList;

    /**
     * 哪些岗位拥有该文件
     */
    private List<String> postIdList;


    /**
     * 生成 放回类 移动的桶的  枚举
     *
     * @param bucketName
     * @return cn.cdeden.resource.api.domain.RemoteFilesInfo
     * @author Yu.
     * @Date 2024/12/5 16:19
     **/
    public static RemoteFilesBucketPath of(OssBucketOneEnum bucketName) {
        RemoteFilesBucketPath info = new RemoteFilesBucketPath();
        info.setBucketName(bucketName.getCode());
        info.setInfo("上传文件成功");
        return info;
    }


    /**
     * 生成 放回类 移动的桶的 带放回前端数据
     *
     * @param bucketName
     * @param objectInfo
     * @return cn.cdeden.resource.api.domain.RemoteFilesBucketPath
     * @author Yu.
     * @Date 2024/12/5 16:26
     **/
    public static RemoteFilesBucketPath of(OssBucketOneEnum bucketName, Object objectInfo) {
        RemoteFilesBucketPath info = new RemoteFilesBucketPath();
        info.setBucketName(bucketName.getCode());
        if (objectInfo != null){
            info.setInfo(objectInfo);

//            if (objectInfo instanceof String){
//                info.setInfo(objectInfo);
//            }else if ( objectInfo instanceof JSONObject){
////                info.setInfo(new com.alibaba.fastjson.JSONObject( (Map<String, Object>) objectInfo).toJSONString() );
//            }else {
////                info.setInfo(JSONObject.from(objectInfo).toString());
//            }
        }
        return info;
    }


    /**
     * 生成 放回类 移动的桶的
     *
     * @param bucketName
     * @return cn.cdeden.resource.api.domain.RemoteFilesInfo
     * @author Yu.
     * @Date 2024/12/5 16:19
     **/
    public static RemoteFilesBucketPath of(String bucketName) {
        RemoteFilesBucketPath info = new RemoteFilesBucketPath();
        info.setBucketName(bucketName);
        info.setInfo("上传文件成功");
        return info;
    }

    /**
     * 生成 放回类 移动的桶的 带放回前端数据
     *
     * @param bucketName
     * @param objectInfo
     * @return cn.cdeden.resource.api.domain.RemoteFilesBucketPath
     * @author Yu.
     * @Date 2024/12/5 16:26
     **/
    public static RemoteFilesBucketPath of(String bucketName, Object objectInfo) {
        RemoteFilesBucketPath info = new RemoteFilesBucketPath();
        info.setBucketName(bucketName);
        if (objectInfo != null){
            info.setInfo(objectInfo);
//            if (objectInfo instanceof String){
//                info.setInfo(objectInfo);
//            }else if (objectInfo instanceof JSONObject){
//                info.setInfo(objectInfo.toString());
//            }else {
//                info.setInfo(JSONObject.from(objectInfo).toString());
//            }
        }
        return info;
    }


    /**
     * 生成 放回类 版本的库的位置
     *
     * @param bucketName
     * @return cn.cdeden.resource.api.domain.RemoteFilesInfo
     * @author Yu.
     * @Date 2024/12/5 16:19
     **/
    public static RemoteFilesBucketPath of(String storageId, String bucketName) {
        RemoteFilesBucketPath info = new RemoteFilesBucketPath();
        info.setStorageId(storageId);
        info.setBucketName(bucketName);
        info.setInfo("上传文件成功");
        return info;
    }


    /**
     * 生成 放回类 版本的库的位置 带放回前端数据
     *
     * @param bucketName
     * @return cn.cdeden.resource.api.domain.RemoteFilesInfo
     * @author Yu.
     * @Date 2024/12/5 16:19
     **/
    public static RemoteFilesBucketPath of(String storageId, String bucketName, Object objectInfo) {
        RemoteFilesBucketPath info = new RemoteFilesBucketPath();
        info.setStorageId(storageId);
        if (objectInfo != null){
            info.setInfo(objectInfo);
//            if (objectInfo instanceof String){
//                info.setInfo(objectInfo);
//            }else if (objectInfo instanceof JSONObject){
//                info.setInfo(objectInfo.toString());
//            }else {
//                info.setInfo(JSONObject.from(objectInfo).toString());
//            }
        }
        return info;
    }


    /**
     * 设置模块编号
     * @param moduleId
     * @return
     */
    public RemoteFilesBucketPath setMobileTypeId(String moduleId) {
        this.moduleId = moduleId;
        return this;
    }



    /**
     * 设置权限
     *
     * @param userIdList 用户
     * @param roleIdList 角色
     * @param deptIdList 部门
     * @param postIdList 岗位
     * @return cn.cdeden.resource.api.domain.RemoteFilesBucketPath
     * @author Yu.
     * @Date 2024/12/12 14:03
     **/
    public RemoteFilesBucketPath setPurview(List<String> userIdList, List<String> roleIdList, List<String> deptIdList, List<String> postIdList) {
        this.userIdList = userIdList;
        this.roleIdList = roleIdList;
        this.deptIdList = deptIdList;
        this.postIdList = postIdList;
        return this;
    }

    /**
     * 设置 用户拥有该文件
     *
     * @param userIdList
     * @return cn.cdeden.resource.api.domain.RemoteFilesBucketPath
     * @author Yu.
     * @Date 2024/12/12 16:19
     **/
    public RemoteFilesBucketPath setUserList(List<String> userIdList) {
        this.userIdList = userIdList;
        return this;
    }

    /**
     * 设置 角色拥有该文件
     *
     * @param roleIdList
     * @return cn.cdeden.resource.api.domain.RemoteFilesBucketPath
     * @author Yu.
     * @Date 2024/12/12 16:19
     **/
    public RemoteFilesBucketPath setRoleIdList(List<String> roleIdList) {
        this.roleIdList = roleIdList;
        return this;
    }

    /**
     * 设置 部门拥有该文件
     *
     * @param deptIdList
     * @return cn.cdeden.resource.api.domain.RemoteFilesBucketPath
     * @author Yu.
     * @Date 2024/12/12 16:19
     **/
    public RemoteFilesBucketPath setDeptIdList(List<String> deptIdList) {
        this.deptIdList = deptIdList;
        return this;
    }


    /**
     * 设置 岗位拥有该文件
     *
     * @param postIdList 岗位
     * @return cn.cdeden.resource.api.domain.RemoteFilesBucketPath
     * @author Yu.
     * @Date 2024/12/12 16:19
     **/
    public RemoteFilesBucketPath setPostIdList(List<String> postIdList) {
        this.postIdList = postIdList;
        return this;
    }


}
